﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EasyGameTemplate;

public class E_mineCube : GamePoolAbstract {

    
    public C_mineCubeData mineCubeData;

    private C_mineCubeInput mineCubeInput;
    private C_mineCubeSiki mineCubeSiki;

    public E_mineCube Init(C_mineCubeData c_MineCubeData)
    {
        //初始化属性
        mineCubeData = c_MineCubeData;
        mineCubeInput = GetComponent<C_mineCubeInput>() ?? gameObject.AddComponent<C_mineCubeInput>();
        mineCubeSiki = new C_mineCubeSiki(this);

        //注册事件
        mineCubeInput.OnLongPress = OnLongClick;
        mineCubeInput.OnShortPress = OnShortClick;

        return this;
    }

    public void OnShortClick() {
        //Debug.Log("短按: " + mineCubeData.pointID);
        if (mineCubeData.mineState == D_mineState.Open) return;
        //更新该方块的地雷数量信息
        M_GameManager.Instance.gridManager.CountMine(mineCubeData.pointID);
        mineCubeData.mineState = D_mineState.Open;
        mineCubeSiki.UpdateSiki();
    }

    private void OnLongClick() {
        //Debug.Log("长按: " + mineCubeData.pointID);
        if (mineCubeData.mineState == D_mineState.Open) return;
        mineCubeData.mineState = (mineCubeData.mineState == D_mineState.Default) ? D_mineState.Mark : D_mineState.Default;
        mineCubeSiki.UpdateSiki();
    }
}
